#include"queuesafe.hpp"

#define THREADCOUNT 1


void* cons_start(void* arg){
      QueueSafe* sq=(QueueSafe*)arg; 
      while(1){
       int ret=sq->Pop();
        if(ret==999){
          break;
        }
      }
      return NULL;
}
void* prod_start(void*arg){
     QueueSafe* sq=(QueueSafe *)arg;
     int data=0;
     while(1){
       if(data>=1000){
         break;
       }
        sq->Push(data);
        data++;
     }
     return NULL;
}

int main(){
  QueueSafe* sq=new QueueSafe();
  if(sq==NULL){
    perror("new");
    return 0;
  }
  pthread_t cons[THREADCOUNT],prod[THREADCOUNT];
 //int i=0; 
  for(int i=0;i<THREADCOUNT;i++){
    int ret=pthread_create(&cons[i],NULL,cons_start,(void*)sq);
      if(ret<0){
        perror("pthread_create");
        return 0;
      }
  
  ret = pthread_create(&prod[i],NULL,prod_start,(void*)sq);
  if(ret<0){
    perror("pthread_create");
    return 0;
  }
  }
  // i=0;
  for(int i=0;i<THREADCOUNT;i++){
    pthread_join(cons[i],NULL);
    pthread_join(prod[i],NULL);
  }
  return 0;
}
